#include "friendlistbutton.h"
#include <QLabel>
#include <QHBoxLayout>
#include <QDebug>

//好友列表分组，显示好友，人数等信息的item，每个item表示一组好友
FriendListButton::FriendListButton(QWidget *parent):QLabel(parent)
{

}

/**
 * @brief FriendListButton::mousePressEvent 点击事件
 * @param event
 */
void FriendListButton::mousePressEvent(QMouseEvent* event){
    if(this->isSpread == true){
        this->isSpread = false;
        for (int i = 0; i < this->itemList.length(); i++) {
            this->itemList[i]->setVisible(false);
        }
        //修改箭头样式
        this->leftArrowLabel->setStyleSheet("border-image:url(:/icon/source/login/icon-arrow-normal.png)");
    }else{
        this->isSpread = true;
        for (int i = 0; i < this->itemList.length(); i++) {
            this->itemList[i]->setVisible(true);
        }
        //修改箭头样式
        this->leftArrowLabel->setStyleSheet("border-image:url(:/icon/source/login/icon-arrow-down.png)");
    }
}

void FriendListButton::drawFriendList(){
    QLabel* spaceLabel = new QLabel();//空白标签，站位
    spaceLabel->setFixedSize(10, 10);
    //水平布局放置图标，名称，人数
    this->leftArrowLabel = new QLabel;
    this->leftArrowLabel->setStyleSheet("border-image:url(:/icon/source/login/icon-arrow-normal.png);");
    this->leftArrowLabel->setFixedSize(10, 10);

    QLabel* nameLabel = new QLabel;
    nameLabel->setText(this->listName);
    nameLabel->setAlignment(Qt::AlignVCenter);
    //nameLabel->setStyleSheet("background-color:rgb(255, 255, 0)");//yellow

    QLabel* numLabel = new QLabel;
    QString numString = QString::asprintf("%d/%d", this->onlineNum, this->totalNum);
    numLabel->setText(numString);
    numLabel->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
    numLabel->setStyleSheet("color:#b7b6b7");
    //numLabel->setStyleSheet("background-color:rgb(255, 0, 0)");//red

    QHBoxLayout* layout = new QHBoxLayout;
    layout->addWidget(spaceLabel);
    layout->addWidget(this->leftArrowLabel);
    layout->addWidget(nameLabel);
    layout->addWidget(numLabel);
    layout->setMargin(0);
    layout->setSpacing(0);

    this->setLayout(layout);
}

void FriendListButton::setListName(QString name){
    this->listName = name;
}

void FriendListButton::setTotalNum(int totalNum){
    this->totalNum = totalNum;
}

void FriendListButton::setOnlineNum(int num){
    this->onlineNum = num;
}
